<template>
	<view class="body" :style="{ height: pageHeight + 'px' }">
		<block v-for="(task, index) in taskList" :key="index">
			<view class="task-box" @tap="toTaskPage(task)">
				<view class="task-iocn"><image :src="task.img" mode="aspectFill"></image></view>
				<view class="task-info">
					<view class="task">
						<view class="task-title">{{ task.title }}</view>
						<text class="task-desc">{{ task.desc }}</text>
					</view>
					<view v-if="!task.isDo" class="toTaskPage">去做任务</view>
				</view>
			</view>
		</block>
	</view>
</template>

<script>
import constant from '../../utils/Constant.js';
import showToast from '../../utils/ToastUtils.js';
export default {
	data() {
		return {
			pageHeight: 0,
			taskList: [
			]
		};
	},
	methods: {
		toTaskPage(task) {
			if (!task.isDo && task.toTaskPage) {
				uni.navigateTo({
					url: task.toTaskPage
				});
			}
		},
		loadTask() {
			uni.request({
				url: constant.baseHttpUri + constant.pathUri.task,
				header: constant.authHead(),
				method: 'GET',
				success: res => {
					if (res.data.code === constant.dataCode.OK) {
						this.taskList = res.data.data;
					} else {
						showToast(res.data.msg);
					}
				},
				fail: r => {
					console.log(r);
				}
			});
		}
	},
	onLoad() {
		uni.getSystemInfo({
			success: res => {
				this.pageHeight = res.windowHeight;
				this.loadTask();
			}
		});
	}
};
</script>

<style lang="less" scoped>
.body {
	border: 1rpx solid transparent;
	background: #f5f7fa;
	.task-box {
		margin: 20rpx 40rpx 0;
		background: #ffffff;
		box-shadow: 0 8rpx 16rpx 0 rgba(0, 0, 0, 0.1);
		border-radius: 15rpx;

		display: flex;
		flex-direction: row;
		align-items: center;
		.task-iocn {
			padding-top: 20rpx;
			padding-left: 20rpx;
			margin-right: 10rpx;
			image {
				height: 150rpx;
				width: 150rpx;
			}
		}
		.task-info {
			flex: 1;
			display: flex;
			flex-direction: row;
			justify-content: space-between;
			align-items: center;
			.task {
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: flex-start;

				.task-title {
					color: #333333;
					font-weight: 500;
					font-size: 32rpx;
				}
				.task-desc {
					max-width: 345rpx;
					color: #999999;
					font-size: 28rpx;
					line-height: 34rpx;
				}
			}

			.toTaskPage {
				background: linear-gradient(270deg, #fc80a4 0%, #feb7ba 100%);
				padding: 0 15rpx;
				font-size: 24rpx;
				color: #ffffff;
				border-radius: 15rpx;
				margin-right: 20rpx;
			}
		}
	}
}
</style>
